package com.ukao.cashregister.ui.vipManager;


import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.ukao.cashregister.R;
import com.ukao.cashregister.base.BaseFragment;
import com.ukao.cashregister.base.MvpFragment;
import com.ukao.cashregister.bean.RechargeBean;
import com.ukao.cashregister.bean.UserInfoBean;
import com.ukao.cashregister.listener.OnDialogSureClickListener;
import com.ukao.cashregister.pesenter.VipDetailsTabPesenter;
import com.ukao.cashregister.ui.pickClothing.PickClothingUserInfoRightFragment;
import com.ukao.cashregister.utils.T;
import com.ukao.cashregister.view.VipDetailsTabView;
import com.ukao.cashregister.widget.StateButton;

import java.io.Serializable;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import info.hoang8f.android.segmented.SegmentedGroup;

/**
 * 会员详情
 */
public class VipDetailsTabFragment extends MvpFragment<VipDetailsTabPesenter> implements VipDetailsTabView {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    @BindView(R.id.tab_one)
    RadioButton tabOne;
    @BindView(R.id.tab_two)
    RadioButton tabTwo;
    @BindView(R.id.tab_three)
    RadioButton tabThree;
    @BindView(R.id.tab_four)
    RadioButton tabFour;
    @BindView(R.id.tab_five)
    RadioButton tabFive;
    @BindView(R.id.segmented_group)
    SegmentedGroup segmentedGroup;

    Unbinder unbinder;

    @BindView(R.id.clear_card)
    StateButton clearCard;
    @BindView(R.id.vip_frament_layout)
    FrameLayout vipFramentLayout;

    private List<RechargeBean> mRechargeList;
    private BaseFragment[] mFragment = new BaseFragment[5];
    private String classType;
    private UserInfoBean.UserBean useIdParam;
    private String userId;

    public static VipDetailsTabFragment newInstance(String classType, Serializable useIdParam) {
        VipDetailsTabFragment fragment = new VipDetailsTabFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, classType);
        args.putSerializable(ARG_PARAM2, useIdParam);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            classType = getArguments().getString(ARG_PARAM1);
            useIdParam = (UserInfoBean.UserBean) getArguments().getSerializable(ARG_PARAM2);

        }
    }

    @Override
    protected VipDetailsTabPesenter createPresenter() {
        return new VipDetailsTabPesenter(this);
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_vipdetails, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
        initListener();
    }

    @Override
    protected void initView() {
        mFragment[0] = OftenPlaceFragment.newInstance(useIdParam, "");
        mFragment[1] = ConsumeRecordFragment.newInstance(1, useIdParam);
        mFragment[2] = ConsumeRecordFragment.newInstance(2, useIdParam);
        UserInfoBean.UserBean.InfoBeanX useInfo = useIdParam.getInfo();
        mFragment[3] = PickClothingUserInfoRightFragment.newInstance(true, useInfo.getPhone(), useInfo.getId());
        mFragment[4] = ConsumeRecordFragment.newInstance(3, useIdParam);
        loadMultipleRootFragment(R.id.vip_frament_layout, 0,
                mFragment);
        tabOne.setChecked(true);
        userId = useIdParam.getInfo().getId();

    }

    @Override
    protected void initListener() {
        super.initListener();
        segmentedGroup.setOnCheckedChangeListener(mOnCheckListener);
    }


    private RadioGroup.OnCheckedChangeListener mOnCheckListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
            switch (checkedId) {
                case R.id.tab_one:
                    showHideFragment(mFragment[0]);
                    break;
                case R.id.tab_two:
                    showHideFragment(mFragment[1]);
                    break;
                case R.id.tab_three:
                    showHideFragment(mFragment[2]);
                    break;
                case R.id.tab_four:
                    showHideFragment(mFragment[3]);
                    break;
                case R.id.tab_five:
                    showHideFragment(mFragment[4]);
                    break;
                default:
            }
        }

    };


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void loadFault(String message) {
        T.show(message);
    }

    @Override
    public void rechargeTableSucceed(List<RechargeBean> mRechargeList) {
        this.mRechargeList = mRechargeList;
    }




        @Override
        public void rechargeSucceed (String msg){
            T.show(msg);

}

        @OnClick({ R.id.clear_card})
        public void onViewClicked (View view){
            switch (view.getId()) {


                case R.id.clear_card:
                    break;
            }
        }




;
}
